<template>
  <div class="tab-control">
    <div v-for="(item, index) in titles" @click="itemClick(index)"
         class="tab-control-item">
      <span :class="{'active' :currentIndex == index}">{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabControl",
    props: {
      titles: Array,
      default() {
        return []
      }
    },
    data() {
      return {
        currentIndex: 0
      }
    },
    methods: {
      itemClick(itemIndex) {
        this.$emit('tabClick', itemIndex)
      },
    }
  }
</script>

<style scoped>
  .tab-control {
    display: flex;
    text-align: center;
    font-size: 17px;
    height: 40px;
    line-height: 40px;
    background-color: var(--color-background);
  }

  .tab-control-item {
    flex: 1;
  }

  .active {
    color: var(--color-high-text);
    padding: 0px 5px 3px 5px;
    border-bottom: 2px solid var(--color-high-text);
  }
</style>
